/*
* Codebook.h
* Codebook Class
*
* author : T. D. Gamage
*/

#pragma once
#include <string>
#include <cv.h>
#include <highgui.h>

using namespace std;

#define CHANNELS 3
// For connected components:
// Approx.threshold - the bigger it is, the simpler is the boundary
//
#define CVCONTOUR_APPROX_LEVEL 2
// How many iterations of erosion and/or dilation there should be
//
#define CVCLOSE_ITR 1

typedef struct ce {
    uchar learnHigh[CHANNELS]; //High side threshold for learning
    uchar learnLow[CHANNELS]; //Low side threshold for learning
    uchar max[CHANNELS]; //High side of box boundary
    uchar min[CHANNELS]; //Low side of box boundary
    int t_last_update; //Allow us to kill stale entries
    int stale; //max negative run (longest period of inactivity)
} code_element;
typedef struct code_book {
    code_element **cb;
    int numEntries;
    int t; //count every access
} codeBook;
class Codebook
{
private: 
    codeBook* codeb;
public:
    Codebook(void);
    int update_codebook(uchar* p,codeBook& c,unsigned* cbBounds,int numChannels);
    int clear_stale_entries(codeBook &c);
    uchar background_diff(uchar* p,codeBook& c,int numChannels,int* minMod,int* maxMod);
    void find_connected_components(IplImage* mask,int poly1_hull0 = 1,float perimScale = 4,int* num = NULL,CvRect* bbs = NULL,CvPoint* centers = NULL);

};